package com.demo.coupon;


import com.demo.AppletConstant;
import com.demo.util.Utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 赠送专享红包
 */
public class PointAcquire {

    public static SimpleDateFormat SDF_HMS = new SimpleDateFormat("yyyyMMddhhmmss");

    public static void main(String[] args) throws Exception {
        //调用接口地址
        String url = "https://open.95516.com/open/access/1.0/point.acquire";

        //拼装参数Map
        Map<String, String> params = new HashMap<String, String>(0);
        params.put("appId", AppletConstant.APP_ID);
        params.put("transSeqId", "");
        params.put("transTs", SDF_HMS.format(new Date()));
        params.put("insAcctId", "");
        params.put("mobile", "");
        params.put("cardNo", "");
        params.put("openId", AppletConstant.openId);
        params.put("acctEntityTp", "");
        params.put("pointId", "");
        params.put("pointSource","");
        params.put("pointAt", "");
        params.put("validBeginTs", "");
        params.put("validEndTs", "");
        params.put("busiInfo", "");
        params.put("transDigest", "");
        params.put("remark", "");
        //生成随即字符串
        String nonceStr = Utils.createNonceStr();
        params.put("nonceStr", nonceStr);

        //生成时间戳
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        params.put("timestamp", timestamp);

        //签名
        String signature = Utils.sign(params, AppletConstant.SIGN_KEY_PACKET);
        params.put("signature", signature);

        //针对敏感字段加密
        Utils.encryptedParamMap(AppletConstant.SYMMETRIC_KEY, params, "mobile", "cardNo");
        //发送请求
        String resultStr = Utils.sendPostGson(url, params);

        System.out.println("-------赠送专享红包:" + resultStr + "---------");
    }

}